/**
 * author      : dormi330
 * date        : 2018/6/26
 * project     : mybatis
 * description : 应用层服务
 */

package com.deep.trade.application;

import com.deep.trade.adaptor.required.member.Member;
import com.deep.trade.adaptor.required.member.MemberService;
import com.deep.trade.application.cart.CartQueryService;
import com.deep.trade.application.cart.CartService;
import com.deep.trade.cart.CartApi;
import com.deep.trade.cart.InDtoCart;
import com.deep.trade.cart.InDtoCartDelete;
import com.deep.trade.cart.query.CartQueryApi;
import com.deep.trade.cart.query.OutDtoCartItem;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CartServiceFacade implements CartApi, CartQueryApi {

    @Autowired
    private CartService cartService;

    @Autowired
    private MemberService memberService;

    @Autowired
    private CartQueryService cartQueryService;

    //========================================== CartApi ==========================================//

    /**
     * 添加sku到购物车
     */
    @Override
    public void addSkuToCart(InDtoCart inDtoCart) throws Exception {
        cartService.addSkuToCart(inDtoCart);
    }

    /**
     * 从 购物车 删除一个sku
     */
    @Override
    public void removeSkuFromCart(InDtoCartDelete inDtoCartDelete) throws Exception {
        cartService.removeSkuFromCart(inDtoCartDelete);
    }

    /**
     * 修改购物车 sku数量
     */
    @Override
    public void alterQuantity(InDtoCart inDtoCart) throws Exception {
        cartService.alterQuantity(inDtoCart);
    }
    //========================================== CartApi ==========================================//


    //========================================== CartQueryApi ==========================================//

    /**
     * 查看 购物车 列表
     */
    @Override
    public PageInfo<OutDtoCartItem> cartOfMember(String tenantCode, String token, int pageNum, int pageSize) throws Exception {
        Member member = memberService.memberOfToken(tenantCode, token);
        return cartQueryService.cartOfMember(tenantCode, member.getId(), pageNum, pageSize);
    }
    //========================================== CartQueryApi ==========================================//

}
